package com.uinnova.product.eam.mvc;

import com.alibaba.fastjson.JSONObject;
import com.binary.framework.web.RemoteResult;
import com.uinnova.product.eam.dto.MeasureEvaluator;
import com.uinnova.product.eam.service.MeasureConfService;
import com.uinnova.product.eam.vo.MeasureConfHistory;
import com.uinnova.product.eam.vo.MeasureConfInfo;
import com.uinnova.product.eam.vo.MeasureConfSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/measure/conf")
public class MeasureConfController {

    @Autowired
    private MeasureConfService measureConfService;

    @PostMapping("/evaluators")
    public RemoteResult evaluators(@RequestBody String body) {
        JSONObject jsonObject = JSONObject.parseObject(body);
        String group = jsonObject.getString("group");
        List<MeasureEvaluator> evaluators =  measureConfService.evaluators(group);
        return new RemoteResult(evaluators);
    }

    @GetMapping("/indicatorClassifies")
    public RemoteResult indicatorClassifies() {
        List<String> indicatorClassifies =  measureConfService.indicatorClassifies();
        return new RemoteResult(indicatorClassifies);
    }

    @PostMapping("/save")
    public RemoteResult save(@RequestBody MeasureConfSaveVo saveVo) {
        measureConfService.saveMeasureConf(saveVo);
        return new RemoteResult("success");
    }

    @GetMapping("/info/{id}")
    public RemoteResult info(@PathVariable Long id) {
        MeasureConfInfo info = measureConfService.info(id);
        return new RemoteResult(info);
    }

    @GetMapping("/latestInfo")
    public RemoteResult latestInfo() {
        MeasureConfInfo info = measureConfService.latestInfo();
        return new RemoteResult(info);
    }

    @GetMapping("/histories")
    public RemoteResult histories() {
        List<MeasureConfHistory> histories = measureConfService.histories();
        return new RemoteResult(histories);
    }

    @GetMapping("/sst/{id}")
    public RemoteResult sst(@PathVariable Long id) {
        measureConfService.sst(id);
        return new RemoteResult("success");
    }
}
